package com.itheima.app;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Test_exe03 {
    public static void main(String[] args) throws SQLException {
        ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("exe03-application-druid.xml");
        DataSource dataSource = (DataSource) app.getBean("dataSource");
        Connection conn = dataSource.getConnection();
        Statement stat = conn.createStatement();
        String sql = "select * from tb_user";
        ResultSet resultSet = stat.executeQuery(sql);
        while (resultSet.next()) {
            String id = resultSet.getString("id");
            String username = resultSet.getString("username");
            System.out.println(id+"--"+username);
        }
    }
}
